package org.dllwh.alibaba.nacos.plugin.datasource.dialect;

import org.dllwh.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;

/**
 * 把今天最好的表现当作明天最新的起点．．～
 * <p>
 * Today the best performance as tomorrow the newest starter!
 *
 * @ClassName AbstractDatabaseDialect
 * @Description 抽象数据库方言
 * <p>
 * 默认限制 mysql、postgresql
 * @Date 2024-11-23 10:58
 * @版本 V 1.0.1
 * @since JDK 17
 */
public abstract class AbstractDatabaseDialect implements DatabaseDialect {
    @Override
    public int getPagePrevNum(int page, int pageSize) {
        return (page - 1) * pageSize;
    }

    @Override
    public int getPageLastNum(int page, int pageSize) {
        return pageSize;
    }

    @Override
    public String getLimitTopSqlWithMark(String sql) {
        return sql + " LIMIT ? ";
    }

    @Override
    public String getLimitPageSqlWithMark(String sql) {
        return sql + " LIMIT ?,? ";
    }

    @Override
    public String getLimitPageSql(String sql, int pageNo, int pageSize) {
        return sql + "  LIMIT " + getPagePrevNum(pageNo, pageSize) + " , " + pageSize;
    }

    @Override
    public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize) {
        return sql + "  LIMIT " + startOffset + " , " + pageSize;
    }

    @Override
    public String[] getReturnPrimaryKeys() {
        return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
    }
}
